﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Cinser.DataTranslate
{
    public abstract class TranslateDalBase
    {
        /// <summary>
        /// 根据表名条件语句获取数据表
        /// </summary>
        public abstract DataTable GetDataList(string tbName, string sqlWhere = "1=1");

        /// <summary>
        /// 添加一行数据，通过自动获取表主键和唯一键来判断是否为更新。
        /// </summary>
        public abstract bool Add(string tbName, DataRow dr);

        /// <summary>
        /// 添加一行数据，通过给定唯一列组来判断是否为更新。
        /// </summary>
        public abstract bool Add(string tbName, DataRow dr, string[] keysColumns);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="tbName">表名</param>
        /// <param name="dr">更新为DR</param>
        /// <param name="keysColumns">条件列名</param>
        /// <param name="keyValues">条件值</param>
        /// <returns></returns>
        public abstract bool Update(string tbName, DataRow dr, string[] keysColumns, string[] keyValues);
        
        /// <summary>
        /// 获取所有用户表
        /// </summary>
        /// <returns></returns>
        public abstract List<string> GetAllTableNames();

        /// <summary>
        /// 判断某表是否存在
        /// </summary>
        /// <param name="tbName"></param>
        /// <returns></returns>
        public abstract bool IsExistTable(string tbName);

        /// <summary>
        /// 获取表的所有列名
        /// </summary>
        public abstract List<string> GetColumns(string tbName);

        public bool CanConnected
        {
            get
            {
                try
                {
                    List<String> result = GetAllTableNames();
                    return result != null && result.Count > 0;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
    }
}
